package com.songcha.module_bookdetail.ui.adapter

import android.view.View
import androidx.databinding.ViewDataBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.songcha.library_common.util.GlideUtil
import com.songcha.library_common.util.TimeUtil
import com.songcha.module_bookdetail.R
import com.songcha.module_bookdetail.bean.BookCommentListBean
import com.songcha.module_bookdetail.databinding.BookdetailItemCommentBinding
import com.songcha.module_bookdetail.ui.dialog.CommentReportDialog

class BookCommentAdapter<DB:ViewDataBinding>(list:MutableList<BookCommentListBean.DataBean.CommentBean>, val showReport:Boolean=false):BaseQuickAdapter<BookCommentListBean.DataBean.CommentBean,BaseDataBindingHolder<DB>>(R.layout.bookdetail_item_comment,list) {
    init {
        addChildClickViewIds(R.id.bookdetail_btn_report)
    }

    override fun convert(holder: BaseDataBindingHolder<DB>, item: BookCommentListBean.DataBean.CommentBean) {
        val db=holder.dataBinding as BookdetailItemCommentBinding
        db.bookdetailTvCommentUser.text=item.userNick

        GlideUtil.loadNetImage(db.bookdetailIvAvatar,item.avatar)
        db.bookdetailRatingComment.setScore(item.starNumber)
        db.bookdetailTvComment.text=item.content

        db.bookdetailBtnReport.apply {
            if(showReport){
                visibility= View.VISIBLE
            }else{
                visibility= View.GONE
            }
            setOnClickListener {
                val dialog=CommentReportDialog(context,item.bookId.toString(),item.id)
                dialog.show()
            }
        }

        db.bookdetailTvCommentTime.apply {
            text=item.createTime
            if(showReport){
                visibility= View.VISIBLE
            }else{
                visibility= View.GONE
            }
        }

        if(item.vipLastTime!=null && item.vipLastTime.isNotBlank() && TimeUtil.timeString2Stamp(item.vipLastTime)>System.currentTimeMillis()){
            db.bookdetailIvVip.visibility=View.VISIBLE
        }else{
            db.bookdetailIvVip.visibility=View.GONE
        }

    }
}